package jzoffer.q02singleton;

/**
 * Author:   dengxin
 * Date:     2020/4/17 5:13 下午
 * 线程安全的懒汉式：静态内部类
 * 1.私有化单例类的构造函数
 * 2.定义静态内部类SingletonHolder，SingletonHolder包括类型为Singleton静态实例变量
 * 3.Singleton的创建实例的getInstance方法调用静态内部类SingletonHolder时才会初始化Singleton实例
 */
public class Singleton {

    private Singleton() {}

    private static class SingletonHolder {
        private static Singleton instance = new Singleton();
    }

    public Singleton getInstance() {
        return SingletonHolder.instance;
    }
}
